<template>
<div>
  <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="60%"
  >
    <span>宿舍信息</span>
    <el-form :model="xyDormInfo">
      <el-row :gutter="10">
        <el-col :span="8">
          <el-form-item label="宿舍名称:">
            <el-input v-model="xyDormInfo.name" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="宿舍位置:">
            <el-input v-model="xyDormInfo.position" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="宿舍描述:">
            <el-input v-model="xyDormInfo.bak" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="3" class="dromlist">
          宿舍类型:
        </el-col>
        <el-col :span="5">
          <el-select v-model="xyDormInfo.type" placeholder="请选择">
            <el-option
                v-for="item in options"
                :key="item.type"
                :label="item.label"
                :value="item.type">
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="3" class="dromlist">
          入住时间:
        </el-col>
        <el-col :span="5">
          <el-date-picker
              v-model="xyDormInfo.startTime"
              type="date"
              placeholder="选择日期"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-col>
        <el-col :span="3" class="dromlist">
          离开时间:
        </el-col>
        <el-col :span="5">
          <el-date-picker
              v-model="xyDormInfo.endTime"
              type="date"
              placeholder="选择日期"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-col>
      </el-row>


    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="repl">取 消</el-button>
        <el-button type="primary" @click="getAdd">确 定</el-button>
      </span>
  </el-dialog>

</div>

</template>

<script>
import drom from '@/api/xy/drom'
import resdata from '@/utils/count'
export default {
name: "DromLog",
data(){
return{
  dialogVisible:false,
  xyDormInfo:{},
  options: [{
    type: 0,
    label: '男生宿舍'
  }, {
    type: 1,
    label: '女生宿舍'
  }, {
    type: 2,
    label: '未知'
  }],
}

},
methods:{
  //显示弹出的框
  showlog(val){
this.dialogVisible = true;
if (val){
  this.xyDormInfo.id = val
  drom.dromDetail({
    id:val
  })
      .then(res=>{

        this.xyDormInfo=res.data
      })
}


  },
  repl(){
    this.dialogVisible=false;
    this.xyDormInfo={}
  },
  getAdd(){
    this.dialogVisible = false;
    console.log(this.xyDormInfo)
    let flag ;
    if(this.xyDormInfo.id){
      flag = drom.dromUpdat
    }else {
      flag = drom.dromSave
    }

    let xyDormInfo = this.xyDormInfo;

    flag({
      xyDormInfo
    })
        .then(res=>{
          console.log(res.code)

          if (res.code == true){
            this.$message('保存成功')
            this.xyDormInfo={}
            // 发送到子组件来进行刷新
            this.$emit('refresh')
          }else {
            this.$message('请求失败')
          }
        })
  // resdata(this,'xyDormInfo')

  }
}
}
</script>

<style lang="scss" scoped>

</style>
